﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Delta_util.Clases;

namespace Delta_editoresWeb.GridColumns
{
    public class ColumnaBarraProgreso : TemplateField
    {
        public string DataField { get; set; }

        public ColumnaBarraProgreso()
        {

            this.ItemTemplate = new ItemBarraProgresoTemplate(this);
        }
    }

    public class ItemBarraProgresoTemplate : ITemplate
    {
        protected ColumnaBarraProgreso datos;
        public ItemBarraProgresoTemplate(ColumnaBarraProgreso padre) { datos = padre; }
        string nombre = "";
        public void InstantiateIn(System.Web.UI.Control container)
        {


            LiteralControl ltlinkFinal = new LiteralControl();
            ltlinkFinal.DataBinding += new EventHandler(ltlinkFinal_DataBinding);
            container.Controls.Add(ltlinkFinal);

        }

        void ltlinkFinal_DataBinding(object sender, EventArgs e)
        {
            LiteralControl ctrl = (LiteralControl)sender;
            IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
            ctrl.Page.Header.Controls.Add(Utilerias.CrearLinkCSS(ctrl.Page, this.GetType(), "Delta_editoresWeb.Plugins.css.gral.css"));
            object bound_value_obj = DataBinder.Eval(data_item_container.DataItem, datos.DataField);
            nombre = datos.DataField + "_" + data_item_container.DataItemIndex.ToString();
            ctrl.Text = "<div id='progressBar_" + nombre + "' class='default'><div></div></div>";
            Utilerias.ExecScript(ctrl.Page, "progress(" + bound_value_obj.ToString() + ", $('#progressBar_" + nombre + "'));", "fijar_valor_" + DateTime.Now.Ticks.ToString() , true);
        }

    }
}
